package com.evildog.workspace.gateway.provider;


import com.evildog.workspace.common.enums.CommonCustomExceptionDesc;
import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 请求响应返回
 */
public class ResponseProvider {


    /**
     * 未授权
     */
    public static Map<String, Object> unAuth() {
        return response(HttpStatus.UNAUTHORIZED.value(), CommonCustomExceptionDesc.UNAUTHORIZED);
    }

    /**
     * 服务器异常
     */
    public static Map<String, Object> forbidden() {
        return response(HttpStatus.FORBIDDEN.value(), CommonCustomExceptionDesc.FORBIDDEN);
    }

    /**
     * 构建返回的JSON数据格式
     *
     * @param status  状态码
     * @return
     */
    public static Map<String, Object> response(int status, CommonCustomExceptionDesc desc) {
        Map<String, Object> map = new HashMap<>(16);
        map.put("code", status);
        map.put("message", desc.getMessage());
        map.put("data", null);
        return map;
    }

	/**
	 * 构建返回的JSON数据格式
	 *
	 * @param status  状态码
	 * @param message 信息
	 * @return
	 */
	public static Map<String, Object> response(int status, String message) {
		Map<String, Object> map = new HashMap<>(16);
		map.put("code", status);
		map.put("message", message);
		map.put("data", null);
		return map;
	}

}
